using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Bullet : MonoBehaviour
{

    private int speed = 10;
    Vector3 dir = Vector3.zero;
    float time = 0;

    public delegate void MoveFun(GameObject obj);
    private MoveFun moveFun;
    private void Awake()
    {
        this.moveFun = new MoveFun((obj) =>
        {
            obj.transform.Translate(dir * speed * Time.deltaTime, Space.World);
        });
    }
    public void SetParam(MoveFun moveFun)
    {
        this.moveFun = moveFun;
    }


    // Update is called once per frame
    void Update()
    {
        time += Time.deltaTime;
        if( time > 3.0f)
        {
            time = 0;
            BulletPool.GetInstance().DeSpwan(this.gameObject);
        }
        this.moveFun(this.gameObject);

    }

    private void OnTriggerEnter(Collider other)
    {
        if (other.gameObject.CompareTag("Player"))
        {
            PlayerController pc = other.gameObject.GetComponent<PlayerController>();
            pc.BeAttacked();
        }
    }
}
